import $service from '../../../../service.js';
var that;
const app = getApp();
Page({
  data: {
    log_type:"",
    doctorInfo: {},
    doctorId: '',
  },

  onLoad: function (e) {
    this.setData({
      log_type : e.log_type,      //问诊类型
      doctorId: e.doctorId
    })
  },
  onShow: function () {
    that = this.data;
    this.getDoctorDetail();
  },
  getDoctorDetail() {
    app.http.getDoctorDetail({id: this.data.doctorId}).then(res => {
        this.setData({
          doctorInfo: res.data
        })
    }).catch(err => {
        $service.showToast(err.msg);
    })
  },
  addConsultationFee() {
    wx.showLoading({
      title: "请求支付中",
      mask: true
    });
    wx.login({
      success(res){
        let params = {
          "code": res.code,
          "doctorId": that.doctorId,
          'inquiryType': that.log_type, 
          "totalFee": that.log_type == 1 ? that.doctorInfo.videoInterrogation : that.doctorInfo.textInterrogation
        }
        app.http.addConsultationFee(params).then(res => {
          wx.requestPayment({
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr,
            'package': res.data.packageWx,
            'signType': res.data.signType,
            'paySign': res.data.paySign,
            'success': (result) => {
              if (result.errMsg == 'requestPayment:ok') {
                $service.openPage('../inquiry_inspecting_feeOK/inquiry_inspecting_feeOK?doctorId=' + that.doctorId + '&log_type='+ that.log_type + '&feeId='+ res.data.id)
              }
            },
            'complete': (res) => { 
              console.log(res)
              wx.hideLoading();
            }
          })
        }).catch(err => {
            $service.showToast(err.msg);
        })
      }
    })
  },
})